Euler Problem 63

The 5-digit number, 16807=75, is also a fifth power. Similarly, the 9-digit number, 134217728=89, is a ninth power.

How many n-digit positive integers exist which are also an nth power?


In [1]:
print (9 + sum(9 - int(10**(1-1.0/n)) for n in range(2, 22)))


49

Explanation: The one-digit numbers from 1 to 9 are first powers. Assume that $n \ge 2$.

We wish to count the solutions to $10^{n-1} \le k^n < 10^n$ where $k, n \ge 2$. This equation is equivalent to $10^{1-1/n} \le k \le 9$.